package com.fg.cloud.factory.controller.factory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fg.cloud.framework.controller.BaseController;
import com.fg.cloud.manager.entry.factory.FactoryImagesEntity;
import com.fg.cloud.manager.service.factory.FactoryImagesService;

/**
 * Description:厂商广告图片处理
 * 
 * @author shaoqiping
 * @date 2017年8月3日上午9:18:04
 */
@Controller
@RequestMapping("/factoryImages")
public class FactoryImagesController extends BaseController {
	@Autowired
	private FactoryImagesService imagesService;

	/**
	 * Description:图片新增
	 * 
	 * @param request
	 * @param response
	 * @param file
	 * @param status
	 * @throws Exception
	 * @author shaoqiping
	 * @date 2017年8月3日上午9:18:28
	 */
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	@ResponseBody
	public void save(HttpServletRequest request, HttpServletResponse response, FactoryImagesEntity imagesEntity)
			throws Exception {
//		try {
//			if (imagesEntity == null || StringUtils.isEmpty(imagesEntity.getUrl())) {
//				doResult(response, false, StatusCode.LACKVALUE, null, ResultType.INPUT_NULL);
//				return;
//			}
//			imagesEntity.setFacId(getCurrentFactoryUser().getFacId());
//			int temp = imagesService.insertSelective(imagesEntity);
//			if (temp > 0) {
//				doResult(response, true, StatusCode.SAVESUCCESS, null, ResultType.ADD_SUCCESS);
//			} else {
//				doResult(response, false, StatusCode.SAVEERROR, null, ResultType.ADD_FAULT);
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//			doResult(response, false, StatusCode.EXCEPTIONERROR, null, e.getMessage());
//		}
	}

	/**
	 * Description:图片显示
	 * 
	 * @param request
	 * @param response
	 * @author shaoqiping
	 * @date 2017年8月3日上午9:18:53
	 */
//	@RequestMapping(value = "/details", method = RequestMethod.POST)
//	@ResponseBody
//	public void imagesShow(HttpServletRequest request, HttpServletResponse response) {
//		try {
//			FactoryUserEntity factoryUserEntity = getCurrentFactoryUser();
//			List<FactoryImagesEntity> images = imagesService.selectByFacId(factoryUserEntity.getFacId());
//			doResult(response, true, StatusCode.FINDSUCCESS, images, ResultType.FIND_SUCCESS);
//		} catch (Exception e) {
//			e.printStackTrace();
//			doResult(response, false, StatusCode.EXCEPTIONERROR, null, e.getMessage());
//		}
//	}

	/**
	 * Description:图片批量删除
	 * 
	 * @param request
	 * @param response
	 * @param id
	 * @author shaoqiping
	 * @date 2017年8月3日上午9:19:06
	 */
	@RequestMapping(value = "deletes", method = RequestMethod.POST)
	@ResponseBody
	public void imagesRemove(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(value = "id") String id) {
//		try {
//			Long[] ids = LongUtils.convert(id.split("[, ]+"));
//			if (ids.length == 0 || ids == null) {
//				doResult(response, false, StatusCode.REMOVEERROR, null, ResultType.REMOVE_FAULT);
//				return;
//			}
//			for (Long id1 : ids) {
//				FactoryImagesEntity imagesEntity = imagesService.selectByPrimaryKey(id1);
//				imagesService.deleteFile(imagesEntity.getUrl());
//			}
//			boolean temp = imagesService.deleteByPrimaryKeys(ids);
//			if (temp) {
//				doResult(response, true, StatusCode.REMOVESUCCESS, null, ResultType.REMOVE_SUCCESS);
//			} else {
//				doResult(response, false, StatusCode.REMOVEERROR, null, ResultType.REMOVE_FAULT);
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//			doResult(response, false, StatusCode.EXCEPTIONERROR, null, e.getMessage());
//		}
	}
}
